class LoginUser {
    constructor() {
        this.user = {}
    }
    get(key) {
        const accountStr = localStorage.getItem('loginUser')
        if(accountStr) {
            this.user = JSON.parse(accountStr)
            return key ? this.user[key] : this.user
        } else {
            console.log('获取当前用户失败');
            return key ? "" : {}
        }
    }
    getUsername() {
        if(Object.keys(this.user).length > 0) {
            return this.user.email || this.user.mphone
        } else {
            const accountStr = localStorage.getItem('loginUser')
            if (accountStr) {
                this.user = JSON.parse(accountStr)
                return this.user.email || this.user.mphone
            } else {
                console.log('获取当前用户失败');
                return ""
            }
        }
    }
}
export default LoginUser